import 'package:amway_superapp_creator_plugin/routers/application.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

import './router_handler.dart';

class Routes {
  static String root = "/";
  static String guidelist = "/guidelist";
  static String testprovide = "/testprovide";
  static String testprovide1 = "/testprovide1";
  static String testselphoto = "/testselphoto";
  static String changeTheme = "/changeTheme";
  static String mainSettings = "/mainSettings";
  static String tagList = "/tagList";
  static String userIcon = "/userIcon";
  static String recommendProduct = "/recommendProduct";
  static String testPage = "/testPage";
  static String setUserCover = "/setUserCover";
  static final String editdata = "/edit/data";
  static final String selectedcombination = "/selected/combination";
  static final String mycircle = "/my/circle";
  static final String openWebView = "/openWebView";
  static final String MYCIRCLEDETAILSVIDEO = "/myCircleDetails/video";
  static final String MYCIRCLEDETAILSIMAGES = "/myCircleDetails/images";
  static final String SENDCIRCLE = "/sendCircle";
  static final String CREATESPLASHVIEW = "/createSplashView";
  static final String editcircle = "/edit/circle";
  static final String shoplist = "/shop/list";
  static final String shopCategory = "/shop/category";
  static final String CAMERA_TEST = '/cameratest';
  static final String CAMERA_PAGE = '/camerapage';
  static final String LOOK_BIG_IMAGE = '/look/image';
  static final String MULTIMEADIAPREVIEW = "/circle/multimeadiaPreview";
  static final String SENDEDITERPAGE = "/circle/sendEditerPage";
  static final String GUIDEDETAILS = "/home/guideDetails";
  static final String OFFICIALDETAIL = "/circle/officialdetail";



/*  static String demoSimple = "/demo";
  static String demoSimpleFixedTrans = "/demo/fixedtrans";
  static String demoFunc = "/demo/func";
  static String deepLink = "/message";*/

  static void configureRoutes(FluroRouter router) {
    router.notFoundHandler = Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      print("ROUTE WAS NOT FOUND !!!");
    });
    router.define(root, handler: rootHandler);
    router.define(guidelist, handler: guideListHandler);
    router.define(testprovide1, handler: testprovideHandler);
    router.define(testselphoto, handler: testSelPhotoView);
    router.define(editdata, handler: editDataView);
    router.define(selectedcombination, handler: selectedCombinationView);
    router.define(changeTheme, handler: changeThemeView);
    router.define(mainSettings, handler: mainSettingsView);
    router.define(tagList, handler: tagListView);
    router.define(userIcon, handler: userIconView);
    router.define(testPage, handler: testPageView);
    router.define(recommendProduct, handler: recommendProductView);
    router.define(setUserCover, handler: setCoverViewHander);
    router.define(mycircle, handler: myCircle);
    router.define(openWebView, handler: commonWebView);
    router.define(MYCIRCLEDETAILSVIDEO, handler: myCircleDetailsvideo);
    router.define(MYCIRCLEDETAILSIMAGES, handler: myCircleDetailsImages);
    router.define(SENDCIRCLE, handler: editerCircleTopView);
    router.define(CREATESPLASHVIEW, handler: createSplashView);
    router.define(shopCategory, handler: chooseShop);
    router.define(shoplist, handler: chooseShopList);
    router.define(CAMERA_TEST, handler: cameraTest);
    router.define(LOOK_BIG_IMAGE, handler: lookImage);
    router.define(MULTIMEADIAPREVIEW, handler: multimeadiaPreview);
    router.define(SENDEDITERPAGE, handler: sendEditerPage);
    router.define(GUIDEDETAILS, handler: guideDetails);
    router.define(OFFICIALDETAIL, handler: officialCircleDetail);


  }

  // 对参数进行encode，解决参数中有特殊字符，影响fluro路由匹配
  static Future navigateTo(BuildContext context, String path,
      {Map<String, dynamic> params,
      TransitionType transition = TransitionType.native}) {
    final router = Application.router;
    String query = "";
    if (params != null) {
      int index = 0;
      for (var key in params.keys) {
        var value = Uri.encodeComponent(params[key]);
        if (index == 0) {
          query = "?";
        } else {
          query = query + "\&";
        }
        query += "$key=$value";
        index++;
      }
    }
    print('我是navigateTo传递的参数：$query');
    path = path + query;
    return router.navigateTo(context, path, transition: transition);
  }
}
